<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title></title>
    <#include "/inc/head.ftl"/>
    <@head/>
</head>

<body>
<div class="panel panel-default">
    <div class="panel-body">
        <div class="row">
            <form id="form" action="${contextPath}/cart/checkout" role="form" method="post">
                <div class="col-lg-12">
                    <input id="id" name="orderList.id" type="hidden" value="${(orderList.id)!}" class="form-control">
                    <div class="form-group">
                        <label>总金额</label>
                        <input id="totalPrice" name="orderList.totalPrice" value="${(orderList.totalPrice)!}" class="form-control" readonly>
                    </div>
                    <div class="form-group">
                        <label>已付押金</label>
                        <input id="cashPledge" name="orderList.cashPledge" value="${(orderList.cashPledge)!}" class="form-control" readonly>
                    </div>
                    <div class="form-group">
                        <label>应付</label>
                        <input id="amount"  value="'${(orderList.cashPledge)!}'-0-'${(orderList.totalPrice)!}'-0" class="form-control" readonly>
                    </div>

                    <div class="form-group">
                        <label>实付</label><span id="tips"></span>
                        <input id="payAmount" name="orderList.payAmount" value="" class="form-control" onfocus="initAmount()" autofocus>
                    </div>


                    <div align="right">
                        <button id="btn-submit" type="submit" class="btn btn-default">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!-- /.panel-body -->
</div>
<!-- /.panel -->i
<script>
    $(function() {
        $('form').validate({
            submitHandler: function(form) {
                $(form).ajaxSubmit(function(data) {
                    if (data.result) {
                        parent.layer.msg(data.msg, {
                            time: 1000,
                            icon: 1
                        });
                    } else {
                        parent.layer.msg(data.msg, {
                            time: 1000,
                            icon: 2
                        });
                    }
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                });
            }
        });
    });
    function initAmount(){
        var totalPrice = '${(orderList.totalPrice)!}'-0;
        var cashPledge= '${(orderList.cashPledge)!}'-0;
        var amount = totalPrice - cashPledge;
        if(amount > 0) {
            $("#amount").val(amount);
        }else{
            $("#amount").val(0);
            $("#payAmount").val(0);
            $("#payAmount").blur();
        }
    }

    function validate() {
        var amount = $("#amount").val()-0;
        var payAmount = $("#payAmount").val()-0;
        var result = payAmount - amount;
        if(result < 0){
            $("#btn-submit").css("disabled","disabled");
            $("#tips").html(要求不小于应付金额 + "!");
            $("#tips").css("color","red");

        }else {
            $("#tips").html(通过校验 + "!");
            $("#tips").css("color","green")
        }
    }

</script>
</body>

</html>